package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;

import br.urca.dao.RequerimentoDAO;
import br.urca.model.Requerimento;

public class JPARequerimentoDAO implements RequerimentoDAO {

	private final EntityManager manager;

	public JPARequerimentoDAO() {
		this(null);
	}

	@Inject
	public JPARequerimentoDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public Requerimento getRequerimento(String codigo) {
		try {
			return this.manager
					.createQuery(
							"SELECT r FROM Requerimento r "
									+ "WHERE r.codigo = :codigo ",
							Requerimento.class).setParameter("codigo", codigo)
					.getSingleResult();
		} catch (Exception e) {
			return null;
		}
	}

}
